package io.framework.modules.noise.controller;

import io.framework.common.constant.Constant;
import io.framework.common.page.PageData;
import io.framework.common.utils.Result;
import io.framework.modules.air.dto.AirDTO;
import io.framework.modules.air.dto.AirExDTO;
import io.framework.modules.air.entity.AirCarAutoDataEntity;
import io.framework.modules.air.service.AirCarAutoDataService;
import io.framework.modules.air.service.AirService;
import io.framework.modules.noise.dto.NoiseDayDTO;
import io.framework.modules.noise.dto.NoiseMonitorDTO;
import io.framework.modules.noise.entity.NoiseDay;
import io.framework.modules.noise.service.NoiseDayService;
import io.framework.modules.water.entity.WaterAutoDataEntity;
import io.framework.modules.water.service.WaterAutoDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;


/**
 * 噪音 环境质量监测
 *
 * @author Gujq email
 * @since 1.0.0 2020-06-01
 */
@RestController
@Api(tags = "噪音 环境质量监测")
public class NoiseAutoController {

    @Autowired
    private NoiseDayService noiseDayService;

    @Autowired
    private AirService airService;

    @Autowired
    private WaterAutoDataService waterAutoDataService;

    @Autowired
    private AirCarAutoDataService airCarAutoDataService;

    @GetMapping("noiseAuto/getNoiseRecentTime")
    public Result<NoiseDayDTO> getNoiseSize() {
        NoiseDayDTO noiseDay = noiseDayService.getNoiseRecentTime();
        return new Result().ok(noiseDay);
    }



    @PostMapping("noiseAuto/getNewNoise")
    public Result getNewNoise(@RequestBody List<NoiseDay> noiseList) {

        System.out.println(noiseList.size());

        if (noiseList.size() > 0) noiseDayService.insertBatch(noiseList);

        return new Result();
    }



    @GetMapping("noiseAuto/pageList")
    public Result<PageData<NoiseDayDTO>> pageList(@RequestParam Map<String, Object> params) {
        if (!params.containsKey(Constant.PAGE) || !params.containsKey(Constant.LIMIT)) {
            return new Result<PageData<NoiseDayDTO>>().error("参数错误");
        }
        PageData<NoiseDayDTO> page = noiseDayService.pageList(params);
        return new Result<PageData<NoiseDayDTO>>().ok(page);
    }


    @GetMapping("noiseAuto/getAirRecentTime")
    public Result<AirExDTO> getAirRecentTime(String createTime) {
        List<AirExDTO> airDTO = airService.getAirRecentTime(createTime);
        return new Result().ok(airDTO);
    }


    @GetMapping("noiseAuto/getEnvAutoWaterNewData")
    public Result<List<WaterAutoDataEntity>>  getEnvAutoWaterNewData(@RequestParam Map<String, Object> params) {
        List<WaterAutoDataEntity> page = waterAutoDataService.getWaterAutoListNewData(params);
        return new Result<List<WaterAutoDataEntity>>().ok(page);
    }

    @GetMapping("noiseAuto/getEnvAutoCarAirNewData")
    public Result<List<AirCarAutoDataEntity>>  getEnvAutoCarAirNewData(@RequestParam Map<String, Object> params) {
        List<AirCarAutoDataEntity> page = airCarAutoDataService.getEnvAutoCarAirNewData(params);
        return new Result<List<AirCarAutoDataEntity>>().ok(page);
    }



}